package com.uniledger.test.model;

import android.content.Context;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;

import com.google.gson.annotations.SerializedName;

import java.math.BigDecimal;

public class PayResult implements Parcelable {

    public int flag;
    public String flagStr;

    public String id;

    public String remark;

    public String category;

    @SerializedName("balance")
    public String balance;

    @SerializedName("bank")
    public String bankCard;

    @SerializedName("card_no")
    public String cardNo;

    @SerializedName("sendamount")
    public String amount;

    public String fee;

    @SerializedName("rate")
    public String rate;

    @SerializedName("arriveamount")
    public String arriveAmount;

    @SerializedName("arrivecurrency")
    public String arriveCurrency;

    @SerializedName("name")
    public String receiver;

    @SerializedName("hash")
    public String hashStr;

    public String getHashStr() {
        if (TextUtils.isEmpty(hashStr)) {
            return hashStr;
        } else {
            if (hashStr.length() >= 12) {
                return hashStr.substring(0, 5) + "..." + hashStr.substring(hashStr.length() - 7, hashStr.length());
            } else {
                return hashStr;
            }
        }
    }

    public String state;

    public String errorMessage;


    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(this.flag);
        dest.writeString(this.flagStr);
        dest.writeString(this.id);
        dest.writeString(this.remark);
        dest.writeString(this.category);
        dest.writeString(this.balance);
        dest.writeString(this.bankCard);
        dest.writeString(this.cardNo);
        dest.writeString(this.amount);
        dest.writeString(this.fee);
        dest.writeString(this.rate);
        dest.writeString(this.arriveAmount);
        dest.writeString(this.arriveCurrency);
        dest.writeString(this.receiver);
        dest.writeString(this.hashStr);
        dest.writeString(this.state);
        dest.writeString(this.errorMessage);
    }

    protected PayResult(Parcel in) {
        this.flag = in.readInt();
        this.flagStr = in.readString();
        this.id = in.readString();
        this.remark = in.readString();
        this.category = in.readString();
        this.balance = in.readString();
        this.bankCard = in.readString();
        this.cardNo = in.readString();
        this.amount = in.readString();
        this.fee = in.readString();
        this.rate = in.readString();
        this.arriveAmount = in.readString();
        this.arriveCurrency = in.readString();
        this.receiver = in.readString();
        this.hashStr = in.readString();
        this.state = in.readString();
        this.errorMessage = in.readString();
    }

    public static final Creator<PayResult> CREATOR = new Creator<PayResult>() {
        @Override
        public PayResult createFromParcel(Parcel source) {
            return new PayResult(source);
        }

        @Override
        public PayResult[] newArray(int size) {
            return new PayResult[size];
        }
    };
}
